package cn.tedu.store.mapper;

import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import cn.tedu.store.entity.Cart;
import cn.tedu.store.vo.CartVO;

@RunWith(SpringRunner.class)
@SpringBootTest
public class CartMapperTestCase {

	@Autowired
	CartMapper cartMapper;
	
	@Test
	public void findByCids() {
		Integer[] cids= {10,12};
		List<CartVO> rows = cartMapper.findByCids(cids);
		for (CartVO cartVO : rows) {
			System.err.println(cartVO);
		}
	}
	
	@Test
	public void findByCid() {
		Integer cid=12;
		Cart cart = cartMapper.findByCid(cid);
		System.err.println(cart);
	}

	@Test
	public void findByUid() {
		Integer uid=28;
		List<CartVO> carts = cartMapper.findByUid(uid);
		for (CartVO cart : carts) {
			System.err.println(cart);
		}

	}

	@Test
	public void addnew() {
		Cart cart = new Cart();
		cart.setCreatedTime(new Date());
		cart.setCreatedUser("朱上林");
		cart.setModefiedTime(new Date());
		cart.setModefiedUser("超级管理员");
		cart.setGid(1000002L);
		cart.setNum(5);
		cart.setUid(22);
		Integer rows = cartMapper.addnew(cart );
		if(rows==1) {
			System.err.println("OK");
			return;
		}
		System.err.println("插入错误");
	}

	@Test
	public void updateNum() {
		Integer rows = cartMapper.updateNum(1, 2, "朱依依", new Date());
		if(rows==1) {
			System.err.println("更新成功");
			return;
		}
		System.err.println("添加购物车失败！");
	}

	@Test
	public void findByUidAndGid() {
		Cart cart = cartMapper.findByUidAndGid(28, 1000001L);
		System.err.println(cart);
	}

}
